import 'dart:io';
import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_pdfviewer/pdfviewer.dart';
import 'package:url_launcher/url_launcher.dart';

class PdfPreviewScreen extends StatelessWidget {
  final String pdfPath;
  final String title;

  const PdfPreviewScreen({
    Key? key,
    required this.pdfPath,
    required this.title,
  }) : super(key: key);

  Future<void> _openPdfInSystemViewer() async {
    final file = File(pdfPath);
    final uri = Uri.file(file.path);
    if (await canLaunchUrl(uri)) {
      await launchUrl(uri);
    } else {
      debugPrint('Could not launch $uri');
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
        actions: [
          IconButton(
            icon: const Icon(Icons.open_in_new),
            onPressed: _openPdfInSystemViewer,
            tooltip: '在系统查看器中打开',
          ),
        ],
      ),
      body: SfPdfViewer.file(
        File(pdfPath),
      ),
    );
  }
} 